/*******************************************************************************

This code file produces Tables A7 and A8, respectively "Developer Participation Responses to Variation in 421-a Incentive: Borough and Year Fixed Effects" and "Developer Participation Responses to Variation in 421-a Incentive: Lot and Block Controls."

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
* Load Stata-TeX

	do "$code/modules/stata-tex.do"
	cd "$tables/estimates"
	
*** Load data

	use "$data/clean/cleaned_data.dta", clear
	
********************************************************************************
* Complete table analysis
********************************************************************************
	
*** Logit, No FE

	logit inclusionary_onsite dtaxrate_onsite, cl(nta)	
	store_est_tpl using tablesA7andA8.csv, coef(dtaxrate_onsite) name(logit0_dtax) all
		
*** Logit, borough FEs, expanding controls

	* No controls
	
	logit inclusionary_onsite dtaxrate_onsite i.borough i.yearpermit, cl(nta)
	
	store_est_tpl using tablesA7andA8.csv, coef(dtaxrate_onsite) name(logit1_dtax)  all
	
	forvalues i = 1/5 {
		store_est_tpl using tablesA7andA8.csv, coef(`i'.borough) name(logit1_`i'borough) all
	}
	
	forvalues j = 2004/2015 {
		store_est_tpl using tablesA7andA8.csv, coef(`j'.yearpermit) name(logit1_`j'year) all
	}

	
	* Lot controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot i.borough i.yearpermit, cl(nta)
	store_est_tpl using tablesA7andA8.csv, coef(dtaxrate_onsite) name(logit2_dtax) all
	
	forvalues i = 1/5 {
		store_est_tpl using tablesA7andA8.csv, coef(`i'.borough) name(logit2_`i'borough) all
	}
	
	forvalues j = 2004/2015 {
		store_est_tpl using tablesA7andA8.csv, coef(`j'.yearpermit) name(logit2_`j'year) all
	}
	
	forvalues k = 1/6 {
		store_est_tpl using tablesA7andA8.csv, coef(`k'.lottype) name(logit2_`k'lottype) all
	}
	
	foreach v of varlist $controls_lot_nofvs {
		store_est_tpl using tablesA7andA8.csv, coef(`v') name(logit2_`v') all
	}
	
	* Lot + neighborhood controls
	
	logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.borough i.yearpermit, cl(nta)
	store_est_tpl using tablesA7andA8.csv, coef(dtaxrate_onsite) name(logit3_dtax) all
	
	forvalues i = 1/5 {
		store_est_tpl using tablesA7andA8.csv, coef(`i'.borough) name(logit3_`i'borough) all
	}
	
	forvalues j = 2004/2015 {
		store_est_tpl using tablesA7andA8.csv, coef(`j'.yearpermit) name(logit3_`j'year) all
	}
	
	forvalues k = 1/6 {
		store_est_tpl using tablesA7andA8.csv, coef(`k'.lottype) name(logit3_`k'lottype) all
	}
	
	foreach v of varlist $controls_block $controls_lot_nofvs {
		store_est_tpl using tablesA7andA8.csv, coef(`v') name(logit3_`v') all
	}
	
********************************************************************************
* Create table
********************************************************************************
	
	cat tablesA7andA8.csv

	cd "$code/modules"
	
	capture table_from_tpl, t("$tables/templates/tableA7.tex") ///
						r("$tables/estimates/tableA7.csv") ///
						o("$tables/output/tableA7.tex") 
						
	capture table_from_tpl, t("$tables/templates/tableA7.tex") ///
						r("$tables/estimates/tableA7.csv") ///
						o("$tables_overleaf/tableA7.tex") 
		
	capture table_from_tpl, t("$tables/templates/tableA8.tex") ///
						r("$tables/estimates/tableA8.csv") ///
						o("$tables/output/tableA8.tex") 
						
	capture table_from_tpl, t("$tables/templates/tableA8.tex") ///
						r("$tables/estimates/tableA8.csv") ///
						o("$tables_overleaf/tableA8.tex") 	
